/**
 * Class containing the Gene strategy.
 * @author	081028AW
 */
public class StrategyGene extends Strategy
   {
  /**
   * Encoding for Gene strategy.
   */

   int numDefects;
   static int LengthExpected = 70;
   String previousMoves;
   String gene;
   boolean firstMove = true;

  // 0 = defect, 1 = cooperate

   public StrategyGene(String chromo)
      {
      name = "Gene";
      gene = chromo;
      opponentLastMove = 1;
      numDefects = 0;
      if (gene.length() != LengthExpected)
      {
    	  //error rcm
      }
      }  /* StrategyGene */

   public int nextMove()
      {
	   if (firstMove)
	   {
		   firstMove = false;
		   previousMoves = gene.substring(64);
	   }
	   else
	   {
		   previousMoves += opponentLastMove;
	   }
	
	   int previousMovesIndex = Integer.parseInt(previousMoves, 2);
	  
	   String move = gene.substring(previousMovesIndex, previousMovesIndex+1);
	  
	   int nextMove = Integer.parseInt(move);
	   
	   String previous2Moves = previousMoves.substring(2);
	   previousMoves = previous2Moves + nextMove;
	  
	   return nextMove;
      }  /* nextMove */

   }  /* class StrategyGene */
